package mz.behaveas.model.expectation {

	import mz.behaveas.model.ducktype.Duck;
	import mz.behaveas.model.ducktype.arraysAreEqual;
	/**
	 * @author maxim.zaks@gmail.com
	 */
	public class NotEqualExpectation implements Expectation {

		private var _description : String;
		private var behaviour : Function;
		private var notEqualValue : *;
		private var error : Error;
		private var value : *;

		public function NotEqualExpectation(description : String, behaviour : Function, notEqualValue : *) {
			this.notEqualValue = notEqualValue;
			this.behaviour = behaviour;
			_description = description;
		}

		public function get description() : String {
			return _description;
		}

		public function get isCorrect() : Boolean {
			try {
				value = behaviour();
				if(value is Array && notEqualValue is Array) {
					return !arraysAreEqual(value, notEqualValue);
				}
				if(notEqualValue is Duck){
					return !Duck(notEqualValue).equals(value);
				}
				return value != notEqualValue;
			} catch(e : Error) {
				error = e;
			}
			return false;
		}
		
		public function get report() : String {
			if(isCorrect) {
				return FLAG[0] + " The behavioure was not returning " + notEqualValue + " as expected.";
			} else {
				if(error != null) {
					return FLAG[1] + " The behavioure was interrupted by: " + error;
				}
			}
			return FLAG[1] + " The behavioure returned " + value + " but it was not expected";
		}
		
		public function getError() : Error {
			return error;
		}
		
	}
}
